﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using InputParsing;
using System.Drawing;

namespace DissipativeInputProcessing
{
    class MultipleFilesFramePool : FramePool
    {
        public MultipleFilesFramePool():base()
        {
        }

        public void ReadFramesFromCatalog(DirectoryInfo di)
        {
            var newList = new List<IFrame>();
            if (!di.Exists)
                throw new IOException("Несуществующая директория.");
            foreach (var file in di.GetFiles())
                try
                {
                    newList.Add(new FrameFileProxy(file,new Frame(file.Name)));
                }
                catch(FormatException ex)
                {
                    var ioEx = new IOException(ex.Message, ex);
                    ioEx.Source = file.FullName;
                    throw ioEx;
                }
            Frames = newList;
        }
        public void ReadFramesFromCatalog(string path)
        {
            ReadFramesFromCatalog(new DirectoryInfo(path));
        }
        private float[,] ReadFromFile(FileInfo file)
        {
            float[,] matrix;
            using(var reader = new StreamReader(file.FullName))
                matrix = _parser.ParseToMatrix(reader);
            return matrix;
        }
    }
}
